#include <nanoco.h>
#include <vector>
#include <iostream>
#include <thread>
class TestClass
{
public:
    void do_scheduling()
    {
        m_timeSch();
    }

private:
    nco::SleepScheduler m_timeSch;
};

nco::Task<> co()
{
    for (size_t i = 0; i < 3; i++)
    {
        auto c = clock();
        auto ms = rand() % 10000;
        auto creaeteThread = this_thread::get_id();
        co_await nco::Sleep(ms);
        if (this_thread::get_id() == creaeteThread)
        {
            cout << "\033[0m" << (double)(clock() - c) / CLOCKS_PER_SEC * 1000 << "ms resume ,预计:" << ms << "ms  out thread" << this_thread::get_id() << " in thread" << creaeteThread << endl;
        }
        else
        {
            cout << "\033[31m" << (double)(clock() - c) / CLOCKS_PER_SEC * 1000 << "ms resume ,预计:" << ms << "ms  out thread" << this_thread::get_id() << " in thread" << creaeteThread << endl;
        }
    }
}

void threadfun()
{
    nco::SleepScheduler sp;
    vector<nco::Task<>> cos;
    for (size_t i = 0; i < 100; i++)
    {
        cos.push_back(co());
    }

    cout << "out fun\n";
    while(1)
        sp();
    
    

}

int main(int argn, char **argv)
{
    srand(time(0));
    thread th(threadfun);
    th.detach();

    thread th2(threadfun);
    th2.detach();
    thread th3(threadfun);
    th3.detach();
    thread th4(threadfun);
    th4.detach();
    thread th5(threadfun);
    th5.detach();

    threadfun();

    return 0;
}